package com.xyht.sca_s.student_manage_system.modules.appDynamic.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.appDynamic.entity.req.AppBasicInfoReq;
import com.xyht.sca_s.student_manage_system.modules.appDynamic.service.AppBasicInfoService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 应用基础信息表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-07-26
 */
@RestController
@RequestMapping("/appBasicInfo")
@SecretBody
public class AppBasicInfoController {
    @Resource
    private AppBasicInfoService appBasicInfoService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "添加应用基础设置")
    @PostMapping("/add")
    public ResponseResult addAppBasicInfo(@RequestBody AppBasicInfoReq basicInfoReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return appBasicInfoService.addAppBasicInfo(basicInfoReq, userId);
    }

    @ApiModelProperty(value = "删除应用")
    @PostMapping("/delete")
    public ResponseResult deletedAppBasicInfo(@RequestBody AppBasicInfoReq basicInfoReq) {
        return appBasicInfoService.deletedAppBasicInfo(basicInfoReq);
    }

    @ApiModelProperty(value = "修改基础设置")
    @PostMapping("/update")
    public ResponseResult updateAppBasicInfo(@RequestBody AppBasicInfoReq basicInfoReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return appBasicInfoService.updateAppBasicInfo(basicInfoReq, userId);
    }

    @ApiModelProperty(value = "查询基础设置")
    @GetMapping("/select")
    public ResponseResult selectAppBasicInfo(@RequestParam(value = "id", required = false) String id, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return appBasicInfoService.selectById(id, userId);
    }

    @ApiModelProperty(value = "模板上传")
    @PostMapping("/upload")
    public ResponseResult tableUpload(@RequestParam("file") MultipartFile file, @RequestParam("appId") String appId) {
        return appBasicInfoService.tableUpload(file, appId);
    }

}

